package com.ssm.controller.admin;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ssm.controller.SSMController;
import com.ssm.model.Model;
import com.ssm.model.bean.SsmMenu;
import com.ssm.model.mapper.ActionMapper;
import com.ssm.model.mapper.MenuMapper;
import com.ssm.model.mapper.WebSettingMapper;

/**
 * 菜单控制器
 * @author 危文涛<245108903@qq.com>
 * @version 2016年2月2日 上午11:15:04
 *
 */
@Controller
@RequestMapping(value="menu")
public class MenuController extends AdminBaseController<SsmMenu> {

	@RequestMapping(value="index")
	public String index(HttpServletRequest request)
	{
		request.setAttribute("WEB_TITLE","菜单设置列表");
		this.List2Table(MenuMapper.class,null,request,true);	
		return "/menu/index";
	}
	
	
	@RequestMapping(value="edit")
	public String edit(HttpServletRequest request,SsmMenu menu)
	{
		MenuMapper menuMapper=M.getMapper(MenuMapper.class);
		if(request.getMethod()=="POST")//添加&修改菜单信息
		{
			if(menu.getId()==null)//添加
			{
				menu.setCreatetime(nowTime().toString());
				menu.setCreateuserid(this.getUserID(request));
				menuMapper.insert(menu);
				
			}
			else//修改
			{
				menuMapper.updateByPrimaryKeySelective(menu);
			}
			return "redirect:index";
		}
		else//查看菜单信息和显示菜单界面
		{
			Integer id=null;
			if(request.getParameter("id")!=null)
				id=Integer.parseInt(request.getParameter("id"));
			List<SsmMenu> list=menuMapper.selectName();
			if(id==null)//显示
			{
				request.setAttribute("menulist", list);
				request.setAttribute("WEB_TITLE", "添加菜单设置");
			}
			else//查看
			{
				menu=menuMapper.selectByPrimaryKey(id);
				request.setAttribute("menulist", list);
				request.setAttribute("menu", menu);
				request.setAttribute("WEB_TITLE", "查看菜单设置");
			}
		}
		return "menu/edit";
	}
	
	@RequestMapping(value="changeStatus")
	public String changeStatus(HttpServletRequest request)
	{
		changeStatus(MenuMapper.class,request);
		return "redirect:index";
	}
	
	
	
}
